﻿import $ = require("jquery");
import ko = require("knockout");
import CallLimiter = require("../../utils/CallLimiter");

class Drag {
    public static create() {
        ko.bindingHandlers.DragOver = {
            init: (element, valueAccessor: () => KnockoutObservable<number>|any) => {
                var callback = CallLimiter(valueAccessor());
                $(element).on("manip.dragover", (event, args: { clientX: number; clientY: number }) => {
                    callback(args);
                });
            },
            update: () => { }
        }

        ko.bindingHandlers.HoldDrag = {
            init: (element, valueAccessor: () => KnockoutObservable<number>|any) => {
                var callback = CallLimiter(valueAccessor());
                $(element).on("manip_holddrag", (event, args: { clientX: number; clientY: number }) => {
                    callback(args);
                });
            },
            update: () => { }
        }
    }
}

export = Drag;